#include "gtest/gtest.h"

#include "MEnviroment.h"
#include "Markup.h"
#include "TestMemory.h"

using namespace Marionette;
using namespace std;
TEST(MTypesTest,ImportFromXML)
{
	MEnviroment env;
	MString xmlTypes = \
"<?xml version=\"1.0\"?>\n\
<types>\n\
<DWORD/>\n\
<struct name=\"TestStruct\">\n\
<DWORD name=\"ID\" offset=\"0x00\"/>\n\
<DWORD name=\"X\" offset=\"0x04\"/>\n\
<DWORD name=\"Y\" offset=\"0x08\"/>\n\
<DWORD name=\"EE\" offset=\"0x0c\"/>\n\
</struct>\n\
<struct name=\"aTestStruct1\">\n\
<DWORD name=\"ID\" offset=\"0\"/>\n\
<DWORD name=\"X\" offset=\"4\"/>\n\
<DWORD name=\"Y\" offset=\"8\"/>\n\
<DWORD_Ptr name=\"X_Ptr\" offset=\"0x0c\"/>\n\
</struct>\n\
</types>";
	env.ImportFrom(xmlTypes);
	TestMemory tm;
	DWORD d = 1;
	tm.Push(&d);
	d=2;
	tm.Push(&d);
	d=3;
	tm.Push(&d);
	d=4;
	tm.Push(&d);
	MValue::SetMemory(&tm);

	MValue dd = env.CreateValue("TestStruct","dd",0x0);
	ASSERT_EQ(dd["ID"].Type()->Name(),"DWORD");
	ASSERT_EQ(dd["X"].Type()->Name(),"DWORD");
	ASSERT_EQ(dd["Y"].Type()->Name(),"DWORD");

	ASSERT_EQ(dd["ID"].ToDWORD(),1);
	ASSERT_EQ(dd["X"].ToDWORD(),2);
	ASSERT_EQ(dd["Y"].ToDWORD(),3);
	ASSERT_EQ(dd["EE"].ToDWORD(),4);
	MValue dd1 = env.CreateValue("aTestStruct1","dd1",0x0);
	ASSERT_EQ(dd1["ID"].ToDWORD(),1);
	ASSERT_EQ(dd1["X"].ToDWORD(),2);
	ASSERT_EQ(dd1["Y"].ToDWORD(),3);
	ASSERT_EQ(dd1["X_Ptr"].ToDWORD(),4);
	ASSERT_EQ((*dd1["X_Ptr"]).ToDWORD(),2);

}
